/**
 * 
 */
package br.embedded.socialapp.data;

import java.util.Date;
import java.util.List;

import br.embedded.socialapp.domain.GraphBuilder;
import br.embedded.socialapp.domain.Usuario;
import br.embedded.socialapp.location.Coordenates;

/**
 * @author daniel
 *
 */
public class DataFacade implements PersistenceManager {

	private static DataFacade singleton;
	
	private DataFacade()
	{
	}
	
	public static DataFacade getInstance()
	{
		if (singleton == null)
			singleton = new DataFacade();
		return singleton;
	}
	
	@Override
	public void createUser(String login, String firstName, String lastName, String passwd) {
		CadastroUsuarioDAO.getInstance().create(login, firstName, lastName, passwd);
	}
	
	@Override
	public void updateSocialNetworkId(String login, String socialNetwork, String id)
	{
		CadastroUsuarioDAO.getInstance().updateSocialNetworkId(login, socialNetwork, id);
	}

	@Override
	public Usuario getUserByLogin(String login) {
		return CadastroUsuarioDAO.getInstance().getByLogin(login);
	}
	
	@Override
	public List<Usuario> getUserById(String id) {
		return CadastroUsuarioDAO.getInstance().getById(id);
	}
	
	@Override
	public List<GraphBuilder> getUsers() {
		return FriendshipDAO.getInstance().getUsers();
	}
	
	@Override
	public void addFriendship(String userLogin1, String userLogin2, String network)
	{
		FriendshipDAO.getInstance().create(userLogin1, userLogin2, network.equalsIgnoreCase("orkut") ? 1 : 2);
	}

	@Override
	public boolean doLogin(String login, String passwd) {
		return CadastroUsuarioDAO.getInstance().checkLogin(login, passwd);
	}

	@Override
	public void registerLocation(String login, double latitude, double longitude) {
		LocationRegisterDAO.getInstance().registerLocation(login, latitude, longitude);
	}

	@Override
	public List<Coordenates> getCoordenates(List<Usuario> friendList, Date initialDate, Date endDate) {
		return LocationRegisterDAO.getInstance().getCoordenates(friendList, initialDate, endDate);
	}
	
	@Override
	public boolean checkLogin(String login)
	{
		return CadastroUsuarioDAO.getInstance().checkLogin(login);
	}
}
